home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6067 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  48 lines

  1. Path: bright.ecs.soton.ac.uk!postmaster
  2. From: Alan Williams <acw93r@ecs.soton.ac.uk>
  3. Newsgroups: comp.lang.c++
  4. Subject: Problem inheriting protected types
  5. Date: Thu, 08 Feb 1996 10:44:31 +0000
  6. Organization: Southampton University
  7. Message-ID: <3119D40F.7847@ecs.soton.ac.uk>
  8. NNTP-Posting-Host: mars.ecs.soton.ac.uk
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b6a (Win95; I)
  13.  
  14. Hi all,
  15.  
  16.   I wonder if anyone can shed some light on this problem for me in the 
  17. following code fragment compiled on BC++ 4.52:
  18.  
  19. class X {               // base class
  20.   protected :
  21.     enum Lst {ONE,TWO,THREE};
  22. };
  23.  
  24. class Y : public X {    // derived class: X protected now Y protected
  25.   public :
  26.     void test(int n) { z.a=TWO; }
  27.  
  28.   private :
  29.     Lst y;              // type Lst derived in X - OK
  30.     struct Jim {
  31.       Lst a;            // type Lst derived in X - DOESN'T COMPILE
  32.     } z;
  33. };
  34.  
  35. void main()
  36. {
  37.   Y n;
  38.   n.test(42);
  39. }
  40.  
  41.   I'm trying to use enum type Lst in a privately (or protected) 
  42. declared class in the derived class. Using Lst directly for a member 
  43. works fine, but using it in a sub-class will not compile saying X::Lst 
  44. is not visible. I've tried all sorts, it only works if its declared 
  45. public in X which I dont want. What is wrong ???
  46.  
  47. Alan
  48.